package com.bawei.imageload

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import okhttp3.OkHttpClient
import java.io.InputStream
import java.util.concurrent.TimeUnit

/**
 * @author ZhangRuiPeng
 * @description:
 */
@GlideModule
class OkHttpGlideModule : AppGlideModule(){

    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        val build = OkHttpClient.Builder()
        build.readTimeout(30, TimeUnit.SECONDS)
        build.connectTimeout(30, TimeUnit.SECONDS)
        build.writeTimeout(10, TimeUnit.SECONDS)
        val client = build.build()
        registry.replace(
            GlideUrl::class.java, InputStream::class.java,
            OkHttpUrlLoader.Factory(client))
    }
}